package core;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

import testing.FolderCompresser;

/**
 * @author Mostafa Mahmod Mahmod Eweda
 * <pre>mostafa_eweda17@yahoo.com</pre>
 * @since JDK 1.6
 * @version 1.0
 * 
 * The parent of the compressors that has the common fields and functions provided
 * by the AbstractCompresser
 * 
 * for some of the implementing classes:
 * @see FileCompresser
 * @see FolderCompresser
 */
public abstract class AbstractCompresser
{

	/**
	 * The input Stream from which the reading process is done
	 */
	protected BufferedInputStream in;

	/**
	 * The output Stream in which the writing process is done
	 */
	protected FileChannel writer;

	/**
	 * The source file of the file wanted to be compressed
	 */
	protected File srcFile;

	/**
	 * Defines the needed parameters for compressers
	 * @param source the path of the source file
	 * @param compressed the path of the op file 
	 */
	public AbstractCompresser(String source, String compressed)
	{
		srcFile = new File(source);
		FileOutputStream opStream;
		try {
			opStream = new FileOutputStream(compressed);
			writer = opStream.getChannel();
			in = new BufferedInputStream(new FileInputStream(srcFile));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Writes the table in the file
	 */
	public abstract void writeTable();

	/**
	 * compress the file using the registered table
	 */
	public abstract void compress();

	/**
	 * writes init data without the table
	 */
	public abstract void noTable();

}
